package com.yunkeji.admin.controller.check;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.common.core.validate.AddGroup;
import com.yunkeji.common.core.validate.EditGroup;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.common.utils.poi.ExcelUtil;
import com.yunkeji.dao.vo.UserCheckVo;
import com.yunkeji.system.domain.bo.CheckBo;
import com.yunkeji.system.service.IUserCheckService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 用户信息审核
 *
 * @author zhang
 * @date 2024-07-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userCheck")
public class UserCheckController extends BaseController {

    private final IUserCheckService iUserCheckService;

    /** 审核通过 */
    @SaCheckPermission("system:userCheck:pass")
    @Log(title = "资料-审核通过", businessType = BusinessType.INSERT)
    @PostMapping("/pass")
    public R<Void> pass(@RequestBody CheckBo bo) {
        iUserCheckService.pass(bo);
        return R.ok();
    }

    /** 审核拒绝 */
    @SaCheckPermission("system:userCheck:refuse")
    @Log(title = "资料-审核拒绝", businessType = BusinessType.INSERT)
    @PostMapping("/refuse")
    public R<Void> refuse(@RequestBody CheckBo bo) {
        iUserCheckService.refuse(bo);
        return R.ok();
    }

    /** 查询用户信息审核列表 */
    @SaCheckPermission("system:userCheck:list")
    @GetMapping("/list")
    public TableDataInfo<UserCheckVo> list(CheckBo bo, PageQuery pageQuery) {
        return iUserCheckService.queryPageList(bo, pageQuery);
    }

    /** 导出用户信息审核列表 */
    @SaCheckPermission("system:userCheck:export")
    @Log(title = "用户信息审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CheckBo bo, HttpServletResponse response) {
        List<UserCheckVo> list = iUserCheckService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户信息审核", UserCheckVo.class, response);
    }

    /**
     * 获取用户信息审核详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:userCheck:query")
    @GetMapping("/{id}")
    public R<UserCheckVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iUserCheckService.queryById(id));
    }

    /** 新增用户信息审核 */
    @SaCheckPermission("system:userCheck:add")
    @Log(title = "用户信息审核", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CheckBo bo) {
        return toAjax(iUserCheckService.insertByBo(bo));
    }

    /** 修改用户信息审核 */
    @SaCheckPermission("system:userCheck:edit")
    @Log(title = "用户信息审核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CheckBo bo) {
        return toAjax(iUserCheckService.updateByBo(bo));
    }

    /**
     * 删除用户信息审核
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:userCheck:remove")
    @Log(title = "删除用户信息记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iUserCheckService.deleteWithValidByIds(Arrays.asList(ids), true));
    }



    /** 取消用户真人认证 */
    @SaCheckPermission("system:appUser:cancelRealAuth")
    @PutMapping("/cancelRealAuth")
    @Log(title = "取消真人认证", businessType = BusinessType.UPDATE)
    public R cancelRealAuth(@RequestBody CheckBo bo) {
        iUserCheckService.cancelRealAuth(bo);
        return R.ok();
    }

    /** 颜值设置 */
    @SaCheckPermission("system:userCheck:edit")
    @Log(title = "颜值设置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/faceScore")
    public R setFaceScore(@RequestBody CheckBo bo) {
        iUserCheckService.setFaceScore(bo);
        return R.ok();
    }
}
